Crispo - Excel Challenge 50 2024

excel-challenges
weekly-exercises
Easy Sunday Excel Challenge
Published

December 15, 2024

Illustration for Crispo - Excel Challenge 50 2024

Challenge Description

Easy Sunday Excel Challenge

⭐ ⭐Calculate Cumulative Debt

Solutions

library(tidyverse)
library(readxl)
path = "files/Excel Challenge 15th Dec.xlsx"
input = read_excel(path, range = "B2:D8")
test  = read_excel(path, range = "E2:E8")

result = input %>%
  mutate(
    Debt = Expense - `Daily Budget`, 
    Cumulative_Debt = accumulate(Debt, ~ max(.x + .y, 0), .init = 0)[-1]
  )

all.equal(result$Cumulative_Debt, test$`Cumulative Debt`)
#> [1] TRUE
  • Logic:

    • Reads the workbook range needed for the challenge

    • Builds the intermediate helper columns that drive the final answer

  • Strengths:

    • The R solution stays compact and mirrors the workbook logic closely.
  • Areas for Improvement:

    • The code assumes the workbook layout and named ranges remain stable.
  • Gem:

    • The best part of the solution is choosing a tidy intermediate shape before producing the final answer.
import pandas as pd
from itertools import accumulate

path = "files/Excel Challenge 15th Dec.xlsx"
input = pd.read_excel(path, usecols="B:D", skiprows=1, nrows=7)
test = pd.read_excel(path, usecols="E", skiprows=1, nrows=7)

input['Debt'] = input['Expense'] - input['Daily Budget']
input['Cumulative_Debt'] = list(accumulate(input['Debt'], lambda cum, debt: max(cum + debt, 0)))

print(input['Cumulative_Debt'].equals(test['Cumulative Debt'])) # True
  • Logic:

    • Reads the workbook range needed for the challenge
  • Strengths:

    • The Python version keeps the same rule in a direct pandas-oriented workflow.
  • Areas for Improvement:

    • As with the R version, any workbook layout change would require small adjustments.
  • Gem:

    • The implementation stays close to the stated challenge instead of adding unnecessary complexity.

Difficulty Level

This task is easy to moderate:

  • The business rule is readable, but the workbook still needs a few careful transformation steps.